package com.example.hello.mapper;

import com.example.hello.entity.EmpExpr;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 员工工作经历Mapper接口
 */
@Mapper
public interface EmpExprMapper {
    
    /**
     * 根据员工ID查询工作经历
     */
    @Select("SELECT * FROM emp_expr WHERE emp_id = #{empId} ORDER BY create_time DESC")
    List<EmpExpr> selectByEmpId(@Param("empId") Integer empId);
    
    /**
     * 添加工作经历
     */
    @Insert("INSERT INTO emp_expr (emp_id, company, position, start_date, end_date, create_time, update_time) " +
            "VALUES (#{empId}, #{company}, #{position}, #{startDate}, #{endDate}, #{createTime}, #{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(EmpExpr empExpr);
    
    /**
     * 修改工作经历
     */
    @Update("UPDATE emp_expr SET company = #{company}, position = #{position}, start_date = #{startDate}, " +
            "end_date = #{endDate}, update_time = #{updateTime} WHERE id = #{id}")
    int update(EmpExpr empExpr);
    
    /**
     * 删除工作经历
     */
    @Delete("DELETE FROM emp_expr WHERE id = #{id}")
    int deleteById(@Param("id") Integer id);
    
    /**
     * 根据员工ID删除所有工作经历
     */
    @Delete("DELETE FROM emp_expr WHERE emp_id = #{empId}")
    int deleteByEmpId(@Param("empId") Integer empId);
}
